package com.jy.app.lib.update;

import android.content.Context;

import com.jy.app.lib.bean.BaseEntity;

import java.util.Locale;
import java.util.Map;

 

/**
 * Created by snowdream on 12/31/13.
 */
public class UpdateInfo extends BaseEntity{
    private String appName = null;    //app名字
    private String packageName = null;  // app包名
    private int versionCode = 0;       // 版本代码
    private String versionName = null; //版本名
    private String forceUpdate = "1"; //强制更新
    private String autoUpdate = "1";  //自动更新
    private String apkUrl = null;     //apk下载地址
    private double intervalTime = 0;     //间隔时间 天为单位
    private Map<String, String> updateTips = null;   //更新表述
    private String note = "";
    private long apkSize = 30;   //apk文件大小

    public String getAppName() {
        return appName;
    }

    public void setAppName(String appName) {
        this.appName = appName;
    }


    public void setApkSize(long apkSize) {
        this.apkSize = apkSize;
    }

    public long getApkSize() {

        return apkSize;
    }

    public String getPackageName() {
        return packageName;
    }

    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }

    public int getVersionCode() {
        return versionCode;
    }

    public void setVersionCode(int versionCode) {
        this.versionCode = versionCode;
    }

    public String getVersionName() {
        return versionName;
    }

    public void setVersionName(String versionName) {
        this.versionName = versionName;
    }

    public boolean isForceUpdate() {
        return forceUpdate.equals("0")==true?true:false;
    }

    public void setForceUpdate(String forceUpdate) {
        this.forceUpdate = forceUpdate;
    }

    public boolean isAutoUpdate() {
        return autoUpdate.equals("0")==true?true:false;
    }

    public void setAutoUpdate(String autoUpdate) {
        this.autoUpdate = autoUpdate;
    }

    public String getApkUrl() {
        return apkUrl;
    }

    public void setApkUrl(String apkUrl) {
        this.apkUrl = apkUrl;
    }

    public Map<String, String> getUpdateTips() {
        return updateTips;
    }

    public void setUpdateTips(Map<String, String> updateTips) {
        this.updateTips = updateTips;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public String getUpdateTips(Context context) {
        String tip = "";
        if (context == null ) {
            return tip;
        }
        Locale locale = context.getResources().getConfiguration().locale;
        String language = locale.getLanguage();
        Map<String, String> tips = getUpdateTips();
        if (tips == null) {
            return tip;
        }

        if (language != null && tips.containsKey(language)) {
            tip = tips.get(language);
        } else {
            tip = tips.get("default");
        }
        //Android textview not supporting line break.see http://stackoverflow.com/a/12422965/821624
        return tip.replace("\\n", "\n");
    }

    public int getIntervalTime() {
        return (int)(intervalTime*1000*60*60*24);
    }

    public void setIntervalTime(double intervalTime) {
        this.intervalTime = intervalTime;
    }
}